package com.itheimaoa.web.action.privilege;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheimaoa.domain.PageBean;
import com.itheimaoa.domain.PageInfo;
import com.itheimaoa.domain.QueryResult;
import com.itheimaoa.domain.privilege.Employee;
import com.itheimaoa.service.privilege.IEmployeeService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller("employeeAction")
@Scope("prototype")
public class EmployeeAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Resource
	private IEmployeeService employeeService;

	private Integer page;

	public Integer getPage() {
		if (page == null || page <= 0) {
			page = 1;
		}
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public String list() {
		PageInfo pi = new PageInfo(this.getPage());
		QueryResult<Employee> qr = employeeService.getQueryResult(pi.getFirstIndex(), pi.getPageSize(), null, null, null);
		PageBean<Employee> pb = new PageBean<Employee>(qr.getResult(), qr.getTotalResult());
		ActionContext.getContext().put("pb", pb);
		return "list";
	}
}
